<template>
  <div>

    <template>
      <el-table
        :data="tracks"
        border
        style="width: 100%"
        @selection-change="handleSelectionChange">
        <el-table-column
          type="selection"
          width="55">
        </el-table-column>
        <el-table-column
          prop="dispatchId"
          label="派车单号"
          width="180"
          align="center">
        </el-table-column>
        <el-table-column
          prop="logistics.route"
          label="路线"
          width="180"
          align="center">
        </el-table-column>
        <el-table-column
          prop="logistics.appointedTime"
          label="指派时间"
          width="180"
          align="center">
        </el-table-column>
        <el-table-column
          prop="logistics.cartypeName"
          label="车辆类型"
          width="180"
          align="center">
        </el-table-column>
        <el-table-column
          prop="logistics.carrierName"
          label="承运商"
          width="180"
          align="center">
        </el-table-column>
        <el-table-column
          prop="logistics.carPlate"
          label="车辆"
          width="180"
          align="center">
        </el-table-column>
        <el-table-column
          prop="logistics.driverName"
          label="司机"
          width="180"
          align="center">
        </el-table-column>
        <el-table-column
          prop="logistics.nodeCurrent"
          label="节点"
          width="180"
          align="center">
        </el-table-column>
        <el-table-column
          prop="status"
          label="状态"
          width="180"
          align="center">
        </el-table-column>


        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="danger"
              @click="addRegister(scope.$index, scope.row)">异常登记
            </el-button>
            <el-button
              size="mini"
              type="primary"
              @click="editRegister(scope.$index, scope.row)">修改登记
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="pageSizes"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>

    <el-dialog title="异常登记" :visible.sync="dialogVisible" width="80%" :before-close="handleClose">
      <span>派车单信息</span>

      <el-table :data="Ttrack">
        <el-table-column property="dispatchId" label="派车单号" width="150"></el-table-column>
        <el-table-column property="logistics.route" label="路线" width="200"></el-table-column>
        <el-table-column property="logistics.appointedTime" label="指派时间" width="200"></el-table-column>
        <el-table-column property="logistics.cartypeName" label="车辆类型" width="200"></el-table-column>
        <el-table-column property="logistics.carrierName" label="承运商" width="200"></el-table-column>
        <el-table-column property="logistics.carPlate" label="车辆" width="200"></el-table-column>
        <el-table-column property="logistics.driverName" label="司机" width="200"></el-table-column>
        <el-table-column property="logistics.nodeCurrent" label="节点" width="200"></el-table-column>
      </el-table>
      <br>
      <hr>
      <br>
        <el-form   label-width="80px" :model="Texception" ref="Texception">
          <el-row>
          <el-col :span="12">
          <el-form-item label="当前节点"  style="width: 400px" prop="location">
            <el-input v-model="Texception.location" ></el-input>
          </el-form-item>
          </el-col>
            <el-col :span="12">
          <el-form-item label="事故类型"  style="width: 400px" prop="exceptionType" >
            <el-input v-model="Texception.exceptionType" ></el-input>
          </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
          <el-form-item label="反馈者" style="width: 400px" prop="feedbacker" >
            <el-input v-model="Texception.feedbacker" ></el-input>
          </el-form-item>
            </el-col>
            <el-col :span="12">
          <el-form-item label="发现时间" style="width: 400px" prop="findTime">
            <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="Texception.findTime" type="datetime"></el-date-picker>
          </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col :span="12">
          <el-form-item label="反馈方式" style="width: 400px" prop="feedbackway">
            <el-input v-model="Texception.feedbackway"></el-input>
          </el-form-item>
            </el-col>
            <el-col :span="12">
            <el-form-item label="反馈时间" style="width: 400px" prop="feedbackTime">
              <el-date-picker value-format="yyyy-MM-dd HH:mm:ss" v-model="Texception.feedbackTime" type="datetime"></el-date-picker>
            </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="异常说明" style="width: 500px" prop="introduction">
            <el-input type="textarea"  v-model="Texception.introduction"></el-input>
          </el-form-item>
        </el-form>
      <span slot="footer" class="dialog-footer">
					<el-button @click="dialogVisible = false,cancelUpData()">取 消</el-button>
					<el-button type="primary" @click="dialogVisible = false , addExData()">提 交 登 记</el-button>
        <el-button type="primary" @click="dialogVisible = false , updateData()">提 交 编 辑</el-button>
				</span>
    </el-dialog>

  </div>
</template>

<script>
    export default {
        name: "t_track",
      data(){
        return{
          tracks:[],
          currentPage: 1,
          pageSize: 2,
          total:0,
          pageSizes: [1, 2, 3, 4],
          dialogVisible:false,
          Ttrack:[],
          Texception:{
            location:"",
            exceptionType:"",
            feedbacker:"",
            findTime:"",
            feedbackway:"",
            feedbackTime:"",
            introduction:"",
            trackId:"",
          },
        }
      },
      methods: {
        cancelUpData(){
          this.Texception={
            location:"",
            exceptionType:"",
            feedbacker:"",
            findTime:"",
            feedbackway:"",
            feedbackTime:"",
            introduction:"",
            trackId:"",
          }
        },
        updateData(){
          this.$http({
            method: "PUT",
            url: "http://localhost:8090/tException",
            data: this.Texception
          }).then(resp => {
            this.Texception={
              location:"",
              exceptionType:"",
              feedbacker:"",
              findTime:"",
              feedbackway:"",
              feedbackTime:"",
              introduction:"",
              trackId:"",
            }
          })
        },
        addExData(){
          this.$http({
            method: "POST",
            url: "http://localhost:8090/tException",
            data: this.Texception
          }).then(resp => {
            this.Texception={
              location:"",
                exceptionType:"",
                feedbacker:"",
                findTime:"",
                feedbackway:"",
                feedbackTime:"",
                introduction:"",
                trackId:"",
            }
          })
        },
        findEByTrackId(trackId) {
          this.$http({
            type: "GET",
            url: `http://localhost:8090/tException/${trackId}`
          }).then(resp => {
            console.log(resp);
            console.log(resp.data);
            this.Texception = resp.data;
          })
        },
        handleClose(){
          this.dialogVisible=false;
        },
        findById(trackId) {
          this.$http({
            type: "GET",
            url: `http://localhost:8090/tTrack/${trackId}`
          }).then(resp => {
            console.log(resp);
            console.log(resp.data);
            this.Ttrack = [resp.data];         //饿了吗form的数据类型是对象，table的数据类型是数组，一个对象如何被table接收到？就是

          })
        },
          addRegister(index, row){

            this.dialogVisible=true;
            console.log(row.trackId);
            let trackId = row.trackId;
            this.findById(trackId);
            this.Texception.trackId= trackId;

            //如果把空对象写成null，那么输入框里面输不进去东西，vue中的空对象是{}，空数组是[]
           /* if (this.findEByTrackId(trackId) =={}){
              this.Texception.trackId= trackId;
              this.addExData();
            }else {
              this.findEByTrackId(trackId);
            }
*/
        },
        editRegister(index, row){
          this.dialogVisible=true;
          console.log(row.trackId);
          let trackId = row.trackId;
          this.findEByTrackId(trackId);
        },

        handleSelectionChange(){

        },
        // 页面大小的触发函数
        handleSizeChange(val) {

          //拿到当前的页面大小
          this.pageSize = val;
          //重新加载 数据
          this.findAll(this.currentPage, this.pageSize);
        },
        //当前页面变化触发的函数
        handleCurrentChange(val) {

          this.currentPage = val;
          // 当前第几页发生了变化  重新加载数据
          this.findAll(this.currentPage, this.pageSize);
        },
        //查询数据
        findAll(currentPage, pageSize) {
          this.$http({
            method: "GET",
            url: "http://localhost:8090/tTrack",
            params: {
              currentPage: currentPage,
              pageSize: pageSize
            }
          }).then(resp => {
            // this.houses = resp.data.data.data; // 拿到服务器的 回写数据中的data数据的对象中data数据
            console.log(resp);
            console.log(resp.data.data.data);
            this.tracks = resp.data.data.data;
            this.total = resp.data.data.total;
          })
        },
        },

      created() {

          this.findAll(1, 2);

      }
    }
</script>

<style scoped>

</style>
